
Deploy Your Apps to Digital Ocean
31 December 2020

A guide to deploy ur apps to Digital Ocean
First, Install Node JS version 12. and Npm in Ubuntu Server ( server in Digital Ocean )
- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
- clone github
- add whitelist to your atlas monggodb
Second, Install PM2 project manager for javascript Nodejs You need install this to make app run automaticaly
- npm i -g pm2
- pm2 start server.js
- pm2 status ( to see status )
- pm2 restart server ( to restart )
- pm2 startup ubuntu ( to make automation running when startup )
- pm2 logs ( to see any logs )
okay next step, Set up NGINX PROXY
apt install nginx
ufw enable
ufw allow ssh
ufw status
ufw allow http ( add 80 port )
ufw allow https ( add 433 port )
sudo nano /etc/nginx/sites-available/default
delete all text
add this to server block
server { server_name domain.com www.domain.com; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
service nginx restart
nginx -t
Other option Add SSL with Cloudflare
- sudo rm /etc/nginx/sites-enabled/default
- sudo nano /etc/nginx/conf.d/nginx.conf
- insert this
server {
listen 80;
listen [::]:80;
server_name www.domain.com domain.com; # the hostname
return 302 https://$server_name$request_uri; ## all traffic through port 80 will be forwarded to 443
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
ssl_certificate /etc/ssl/certs/cert.pem; #path to your public key
ssl_certificate_key /etc/ssl/private/cert.key; #path to your private key
server_name www.domain.com domain.com; # the hostname
location / {
proxy_pass http://127.0.0.1:3001; # URL Rest API
}
}
- nano /etc/ssl/certs/cert.pem
- paste certificate key from cloudflare
- nano /etc/ssl/private/cert.key
- paste private key from cloudflare
- nginx -t
- Service nginx reload